/**
 * Created by shenhai on 15/9/22.
 */

angular.module('mis.questionManager.controllers', [])
    .controller('questionCtrl', ['$scope','$http','$routeParams','$location', function ($scope, $http,$routeParams,$location) {

        $scope.currentPage = 1;
        $scope.pageSize = 15;


        var model = $routeParams.model;
        var params = {};
        if(model == '2'){
            params.replies = 'false';
            params.model = model;
            params.category = 'question';

            $scope.category = 'question'
            $scope.replies = 'false';
        };

        //分页
        $scope.pagination = new pagination({currentPage:$scope.currentPage,pageSize: $scope.pageSize,
            url:'http://' + backOfficeHost + '/rest/v1.0/mis/question/questionList/:page/:size',
            ajax: $http,
            success:function(data){
                if(data && data.data) {
                    $scope.questionList = GetCategoryName(data.data.list,'image');
                    $scope.pageNumber = data.data.totalPage;
                    $scope.count = data.data.count;
                    $scope.pagination.totalPage = data.data.totalPage;
                }
                $scope.currentPage = $(".am-active").text();
                $scope.pagination.pageHeader($scope.pageNumber);
                $('#count').text("共"+$scope.pageNumber+"页 有"+$scope.count+"数据");
                console.debug(params);
                params = {};
            },
            error: function(err){
                $scope.questionList = null;
                params = {};
            },
            params: params
        });

        //搜索
        $scope.search = function (current) {

            if (current) {
                $scope.currentPage = $scope.pagination.currentPage;
            }else {
                $scope.pagination.currentPage = 1;
                $scope.currentPage = 1;
            }

            var city = $scope.cascading.getCity(document.getElementById("search-target"));
            var community = $scope.cascading.getVillageId(document.getElementById("search-target"));
            var body = {};

            if (city) body.city = city;
            if (community) body.community = community;
            if ($scope.nickName) body.nickName = $scope.nickName;
            if ($scope.createdBy) body.createdBy = $scope.createdBy;
            if ($scope.desc) body.desc = $scope.desc;
            if ($scope.tag != '') body.tag = $scope.tag;
            if ($scope.replies != '') body.replies = $scope.replies;
            if ($scope.level != '') body.level = $scope.level;
            if ($scope.acrossCity != '') body.acrossCity = $scope.acrossCity;
            if ($scope.sort) body.sort = true;
            if ($scope.category) body.category = $scope.category;

            if ($scope.cityType) body.cityType = $scope.cityType;

            if ($("#startDate").val()) body.startDate = $("#startDate").val() + ':00';
            if ($("#endDate").val()) body.endDate = $("#endDate").val() + ':00';
            if (body.startDate && body.endDate && body.startDate > body.endDate) {
                alert('开始日期不能大于结束日期');
                return;
            };


            $http.post('http://' + backOfficeHost + '/rest/v1.0/mis/question/questionList/' + $scope.currentPage + '/' + $scope.pageSize, body, {
                headers: {'Content-Type': 'application/json;charset=utf-8'}
            }).success(function (data) {

                $scope.questionList = GetCategoryName(data.data.list,'image');
                $scope.pageNumber = data.data.totalPage;
                $scope.count = data.data.count;

                $scope.pagination.totalPage = data.data.totalPage;
                $scope.pagination.pageHeader($scope.pageNumber);
                $scope.pagination.searchParams = body;

                $('#loading').modal("close");

            }).error(function (err) {

                $('#loading').modal("close");

                $scope.questionList = null;
                alert(err);
            });
        };


        //全选列表
        $scope.allSelected = function(){
            $scope.pagination.allSelected();
        };


        //删除问题
        $scope.deleteQuestion = function(question, index) {

            var userRole =  1;
            if(question.createdBy.userType=="talent") {
                userRole = 2;
            };

            var  category = 33;//非求助被管理员删除
            if(question.category == 'secondhand')  category = 34;   //二手被管理员删除
            if(question.category == 'question')  category = 35;     //求助被管理员删除

            var body = {
                questionId: question.objId,
                userId: question.createdBy.objId,
                userRole: userRole,
                category: category
            };

            //console.debug(body);
            $http.post('http://' + backOfficeHost + '/rest/v1.0/mis/question/delete', body, {
                headers: {'Content-Type': 'application/json;charset=utf-8'}
            }).success(function (data) {
                if (data.result.status == 1) {
                    //$scope.search(true);
                    var pageNumber = $(".am-active").text();//当前页码
                    $('#delete-confirm-'+index).modal("close");
                    $scope.pagination.selectPage(pageNumber);
                }else {
                    alert('删除失败');
                }
            }).error(function (err) {
                $scope.questionList = null;
                alert(err);
            });

        };


        // 设置/取消精华帖
        $scope.updateLevel = function(question, level) {

            body = {id:question.objId, question:{level: level? 1:0}};

            $http.post('http://' + backOfficeHost + '/rest/v1.0/mis/question/update', body, {
                headers: {'Content-Type': 'application/json;charset=utf-8'}
            }).success(function (data) {
                if (data.result.status == 1) {
                    question.level = level? 1:0;
                }else {
                    alert(level ? '设置精华帖失败':'取消精华帖失败');
                }
            }).error(function (err) {
                alert(err);
            });

        };

        // 设置/取消同城
        $scope.updateAcrossCity = function(question, level) {

            body = {id:question.objId, question:{acrossCity: level? 1:0}};

            $http.post('http://' + backOfficeHost + '/rest/v1.0/mis/question/update', body, {
                headers: {'Content-Type': 'application/json;charset=utf-8'}
            }).success(function (data) {
                if (data.result.status == 1) {
                    question.acrossCity = level? 1:0;
                }else {
                    alert(level ? '设置同城可见失败':'取消同城可见失败');
                }
            }).error(function (err) {
                alert(err);
            });

        };

        $scope.setTopData = {};
        $scope.setTopShow = function(question,top){
            $scope.setTopData = question;

            $('#doc-modal-top').modal({target: '#doc-modal-top', width: 800, height: 230 });
        };

        //帖子置顶
        $scope.setTop = function(top,question){

            body = {};
            if(top){
                body.id = $scope.setTopData.objId;
                body.isTop  = top;
                body.communityId = $scope.setTopData.community.objId;
                body.category = $scope.setTopData.category;

                /*  宝宝树66小区二次改造    add   guo.xiaomin  20170818   start   */
                // 以下二者任意为空,后台会出错,置顶失败
                if ($("#beginDate_top").val()){
                    body.beginDate = $("#beginDate_top").val() + ':00';
                } else{
                    alert('置顶起始时间不能为空！');
                    return;
                }
                if ($("#endDate_top").val()) {
                    body.endDate = $("#endDate_top").val() + ':00';
                } else{
                    alert('置顶结束时间不能为空！');
                    return;
                }
                /*  宝宝树66小区二次改造    add   guo.xiaomin  20170818   end   */
            }else{
                body.id = question.objId;
                body.isTop  = top;
            };
            /*  宝宝树66小区二次改造    add   chenf  20170731   start   */
            // 置顶flg
            var value  = $('input[name="village"]:checked').val();
            body.topFlg = value;
            /*  宝宝树66小区二次改造    add   chenf  20170731   end   */
            $http.post('http://' + backOfficeHost + '/rest/v1.0/mis/question/setTop', body, {
                headers: {'Content-Type': 'application/json;charset=utf-8'}
            }).success(function (data) {
                if (data.result.status == 1) {
                    //var myDate = new Date();
                    //question.topBeginDate = myDate.toLocaleString( );
                    if(top) {
                        alert('帖子置顶成功');
                    }else{
                        alert('帖子取消置顶成功');
                    };
                    $('#doc-modal-top').modal("close");
                    $scope.search(true);
                }else {
                    if(top) {
                        alert('帖子置顶失败');
                    }else{
                        alert('帖子取消置顶失败');
                    };
                    $('#doc-modal-top').modal("close");
                }
            }).error(function (err) {
                alert(err);
            });
        };

        // 修改帖子
        $scope.updateQuestion = function(question, index) {

            if (!question.desc) {
                alert('帖子内容为空'); return;
            };

            var body = {id:question.objId, question:{desc: question.desc}};
            if (question.category) body.question.category = question.category;

            console.debug(body);

            $http.post('http://' + backOfficeHost + '/rest/v1.0/mis/question/update', body, {
                headers: {'Content-Type': 'application/json;charset=utf-8'}
            }).success(function (data) {
                if (data.result.status == 1) {
                    var pageNumber = $(".am-active").text();//当前页码
                    $('#doc-modal-Detail-'+ index).modal("close");
                    $scope.pagination.selectPage(pageNumber);
                }else {
                    alert('修改失败');
                }
            }).error(function (err) {
                alert(err);
            });

        };


        // 回复
        $scope.repId = "";
        $scope.repPe = false;
        $scope.getRepId = function(temp, repliedBy){
            var obj = temp.target;
            var div =  $(obj.parentNode.parentNode.parentNode).next().children();
            $scope.repId = obj.parentNode.dataset.repId;
            $scope.repName = repliedBy.nickName;
            $scope.repPe = false;

            div.children("input").val(obj.parentNode.dataset.repName);
            div.children(".rep-post").prop("checked",false);
            div.children(".rep-person").prop("checked",true);

        };
        $scope.repPost = function(temp){
            var obj = temp.target;
            $(obj).next().next().children("input").val("");
            $scope.repId = "";
            $scope.repName = "";
        };
        $scope.repPerson = function(temp){
            var obj = temp.target;
            if($(obj).next().val() == "") $scope.repPe = true;
        };

        /* 宝宝树66小区二次改造 后台管理追加删除评论 add wangcan 20170925 start */
        $scope.deleteQuestionReply = function(question, index) {
            // alert("index:"+index);
            var opt ={
                contentId:question.objId,
                replyId:question.replies[index].objId,
                replyBy:question.replies[index].repliedBy.objId
            };

            $http.post('http://' + backOfficeHost + '/rest/v1.0/mis/question/deleteReply',opt, {
                headers: {'Content-Type': 'application/json;charset=utf-8'}
            }).success(function (data) {
                if (data.result.status == 1) {
                    alert('删除成功');
                    // $('#doc-modal-reply-'+index).modal("close");
                    // $scope.search(true);
                    var questionList = $scope.questionList;
                    for (var i = 0, size = questionList.length; i< size; i++){
                        if (question.objId == questionList[i].objId) {
                            $scope.questionList[i].replies.splice(index,1);
                            break;
                        }
                    }
                    //$('#loading').modal({target: '#loading'});
                }else {
                    alert('删除失败');
                }
            }).error(function () {
                alert('删除失败');
            });
        };
        /* 宝宝树66小区二次改造 后台管理追加删除评论 add wangcan 20170926 end */

        $scope.sendReply = function (question, replyDesc,index) {
            var questionId = question.objId;
            //var communityId = question.community.objId;

            if (!replyDesc) {alert('回复内容不能为空！');}


            var number = "66customerservice";

            $http.get('http://' + AppHost + '/rest/v1.0/System/userToken/' + number, {
                headers: {'Content-Type': 'application/json;charset=utf-8'}
            }).success(function (data) {
                var token = data.data.token;

                var fdReply = new FormData();
                fdReply.append('replyDesc', replyDesc);
                if ($scope.repId) fdReply.append('replyTo', $scope.repId);

                $http.post('http://' + AppHost + '/rest/v1.0/Questions/postReplyNew/' + questionId + '/' + token + "/1", fdReply, {
                    transformRequest: angular.identity,
                    headers: {'Content-Type': undefined}
                }).success(function (data) {
                   if (data.result.status == 1) {
                       var temp = {
                           replyDesc: replyDesc,
                           dateReplied: new Date()
                       };
                       temp.repliedBy = {nickName: '小6客服'};

                       $scope.questionList.forEach(function (question) {
                           if (question.objId == questionId) {
                               question.replies.push(temp);
                           }
                       });

                       replyDesc = "";
                       $("#reply").val("");

                       $('#doc-modal-reply-'+ index).modal("close");

                   }else {
                       alert('回复失败');
                   }

                }).error(function (err) {
                    alert('回复失败');
                });
            }).error(function (err) {
                alert('回复失败');
            });


        };


        $scope.exportQuestion = function () {

            var body = {};

            var href = 'http://' + backOfficeHost + '/rest/v1.0/mis/question/exportQuestion/?isValid=true';

            var city = $scope.cascading.getCity(document.getElementById("search-target"));
            var community = $scope.cascading.getVillageId(document.getElementById("search-target"));

            if (city) href += "&city="+ city;
            if (community) href += "&community="+ community;
            if ($scope.nickName) href += "&nickName="+ $scope.nickName;
            if ($scope.createdBy) href += "&createdBy="+ $scope.createdBy;
            if ($scope.desc) href += "&desc="+ $scope.desc;
            if ($scope.tag != '') href += "&tag="+ $scope.tag;
            if ($scope.replies != '') href += "&replies="+ $scope.replies;
            if ($scope.level) href +="&level="+ $scope.level;
            if ($scope.acrossCity) href +="&acrossCity="+ $scope.acrossCity;
            if ($scope.sort) href += "&sort="+ true;
            if ($scope.category) href += "&category="+ $scope.category;
            if ($scope.cityType) href += "&cityType="+ $scope.cityType;

            if ($("#startDate").val()) href += "&startDate="+ $("#startDate").val() + ':00';
            if ($("#endDate").val()) href += "&endDate="+ $("#endDate").val() + ':00';
            if ($("#startDate").val() && $("#endDate").val() && $("#startDate").val() > $("#endDate").val()) {
                alert('开始日期不能大于结束日期');
                return;
            };
            if(!$("#startDate").val() && !$("#endDate").val()){
                alert('请选择发布日期');
                return;
            };

            location.href = href;

        };


        //屏蔽、取消屏蔽问题
        $scope.shieldQuestion = function(question, index,isShow) {


            var body = {
                questionId: question.objId,
                isShow : isShow
            };

            //console.debug(body);
            $http.post('http://' + backOfficeHost + '/rest/v1.0/mis/question/shield', body, {
                headers: {'Content-Type': 'application/json;charset=utf-8'}
            }).success(function (data) {
                if (data.result.status == 1) {
                    //$scope.search(true);
                    question.isShow = isShow? -1:0;

                }else {
                    alert('操作失败');
                }
            }).error(function (err) {
                $scope.questionList = null;
                alert(err);
            });

        };

        // 推送
        $scope.pushQuestion;
        $scope.questionPushShow = function (question){

            $scope.pushQuestion = question;

            $('#doc-modal-push').modal({target: '#doc-modal-push', width: 800, height: 360 });

        };

        $scope.questionPush = function (message){

            var opt ={
                openType :1,
                contentId:  $scope.pushQuestion.objId,
                createdBy:  $scope.pushQuestion.createdBy.objId,
                tag:  '话题',
                message: message,
                aroundCommunity : $scope.pushQuestion.aroundCommunity
            };

            $http.post('http://' + backOfficeHost + '/rest/v1.0/mis/question/questionPush', opt, {
                headers: {'Content-Type': 'application/json;charset=utf-8'}
            }).success(function (data) {

                $('#doc-modal-push').modal("close");
                $('#loading').modal("close");
                if (data.result.status == 1) {
                    alert('推送成功!');
                }else{
                    alert('推送失败!');
                };

            }).error(function (err) {
                $('#doc-modal-push').modal("close");
                $('#loading').modal("close");

                $scope.questionList = null;
                alert(err);
            });
        };


        //级联框
        var cascadData = {
            provinceUrl: 'http://' + backOfficeHost + '/rest/v1.0/backoffice/region/regionPrivince',
            cityUrl: 'http://' + backOfficeHost + '/rest/v1.0/backoffice/region/regionCity',
            cityAreaUrl: 'http://' + backOfficeHost + '/rest/v1.0/backoffice/region/regionCounty',
            villageUrl: 'http://' + backOfficeHost + '/rest/v1.0/mis/community/communityList',
            ajax: $http
        };
        $scope.cascading = new gObj.cascading(cascadData);
        $scope.cascading.paint($(".city-cascading")[0],true);



    }]).controller('replyAtCtrl', ['$scope','$http','$routeParams','$location', function ($scope, $http, $routeParams, $location) {


        $scope.currentPage = 1;
        $scope.pageSize = 15;

        var model = $routeParams.model;
        var params = {};
        if(model == '1'){
            params.status = 1;
            $scope.status = 1;
        };

        //分页
        $scope.pagination = new pagination({currentPage:$scope.currentPage,pageSize: $scope.pageSize,
            url:'http://' + backOfficeHost + '/rest/v1.0/mis/question/replyAtList/:page/:size',
            ajax: $http,
            success:function(data){
                $scope.atList = data.data.list;
                $scope.pageNumber = data.data.totalPage;
                $scope.count = data.data.count;

                $scope.currentPage = $(".am-active").text();
                $scope.pagination.totalPage = data.data.totalPage;
                $scope.pagination.pageHeader($scope.pageNumber);
                $('#count').text("共"+$scope.pageNumber+"页 有"+$scope.count+"数据");
            },
            error: function(err){
                $scope.atList = null;
            },
            params: params
        });

        //全选列表
        $scope.allSelected = function(){
            $scope.pagination.allSelected();
        };


        $scope.update = function (at) {

            var body = {id:at.objId, status:false};

            $http.post('http://' + backOfficeHost + '/rest/v1.0/mis/question/replyAtUpdate', body, {
                headers: {'Content-Type': 'application/json;charset=utf-8'}
            }).success(function (data) {
                at.status = false;
            }).error(function (err) {
                alert(err);
            });
        };

        $scope.detail = function (contentId,category){
            $("#detail_box").css("display","block");
            $("#mask_box").css("display","block");
            $("#iframe_box").attr("src","../../partials/cs/atcs_detail.html?contentId="+contentId+"&category="+category);
        };

        //搜索
        $scope.search = function (btn) {

            var opt = {};
            if ($scope.status) opt.status = $scope.status;

            $http.post('http://' + backOfficeHost + '/rest/v1.0/mis/question/replyAtList/:' + 1 + '/' + $scope.pageSize, opt, {
                headers: {'Content-Type': 'application/json;charset=utf-8'}
            }).success(function (data) {
                $scope.atList = data.data.list;
                $scope.pageNumber = data.data.totalPage;
                $scope.count = data.data.count;

                $scope.pagination.totalPage = data.data.totalPage;
                $scope.pagination.pageHeader($scope.pageNumber);
                $scope.pagination.searchParams = opt;
            }).error(function (err) {
                alert(err);
            });

        };


    }]).controller('questionReportCtrl', ['$scope','$http', '$location', function ($scope, $http, $location) {


        $scope.currentPage = 1;
        $scope.pageSize = 15;

        var commId = '1';

        $scope.reportStatus = 0;
        /*  宝宝树66小区二次改造    add   chenf  20170821   start   追加举报区分闲置和帖子*/
       /* var params = {reportStatus:0};*/
        var params = {reportStatus:0,statusFlg:1};
        /*  宝宝树66小区二次改造    add   chenf  20170821   end   追加举报区分闲置和帖子*/
        //分页
        $scope.pagination = new pagination({currentPage:$scope.currentPage,pageSize: $scope.pageSize,
            url:'http://' + backOfficeHost + '/rest/v1.0/mis/question/questionReportList/:page/:size',
            ajax: $http,
            success:function(data){
                if(data && data.data) {
                    console.debug(data.data.list);
                    $scope.questionList = data.data.list;
                    $scope.pageNumber = data.data.totalPage;
                    $scope.count = data.data.count;

                    $scope.pagination.totalPage = data.data.totalPage;
                }
                $scope.currentPage = $(".am-active").text();
                $scope.pagination.pageHeader($scope.pageNumber);
                $('#count').text("共"+$scope.pageNumber+"页 有"+$scope.count+"数据");
                /*  宝宝树66小区二次改造    add   chenf  20170821   start   追加举报区分闲置和帖子*/
                $scope.statusFlg = $('#status').val();
                /*  宝宝树66小区二次改造    add   chenf  20170821   end   追加举报区分闲置和帖子*/
            },
            error: function(err){
                $scope.questionList = null;
            },
            params: params
        });

        ////全选列表
        //$scope.allSelected = function(){
        //    $scope.pagination.allSelected();
        //};


        //搜索
        $scope.searchReport = function (current) {

            if (current) {
                $scope.currentPage = $scope.pagination.currentPage;
            }else {
                $scope.pagination.currentPage = 1;
                $scope.currentPage = 1;
            }

            var community = $scope.cascading.getVillageId(document.getElementById("search-target"));
            /*  宝宝树66小区二次改造    add   gct  20170901   start   */


            var city = $scope.cascading.getCity(document.getElementById("search-target"));
            var communityVal=$scope.cascading.getVillage(document.getElementById("search-target"));
            /*  宝宝树66小区二次改造    add   gct  20170901   end   */


            //var body = community ? {community:community}:{community:'1'};

            var body = {};
            /*  宝宝树66小区二次改造    mod   gct  20170901   start   */
          /*  if(community)
            {
                (body.community = community);
            } 旧*/

            if(community)
            {
                (body.community = community);
            }
            else
                {
                    body.city=city;
                    body.communityValue=communityVal;
                };
            /*  宝宝树66小区二次改造    mod   gct  20170901   end   */
            if($scope.reportStatus!= null && $scope.reportStatus !=-2) (body.reportStatus = $scope.reportStatus);

            /*  宝宝树66小区二次改造    add   chenf  20170821   start   追加举报区分闲置和帖子*/
            body.statusFlg = $('#status').val();
            /*  宝宝树66小区二次改造    add   chenf  20170821   end   追加举报区分闲置和帖子*/
            console.debug( $scope.currentPage);

            $http.post('http://' + backOfficeHost + '/rest/v1.0/mis/question/questionReportList/' + $scope.currentPage + '/' + $scope.pageSize, body, {
                headers: {'Content-Type': 'application/json;charset=utf-8'}
            }).success(function (data) {
                /*  宝宝树66小区二次改造    mod   gct  20170901   start   */

               /* $scope.questionList = data.data.list;
                $scope.pageNumber = data.data.totalPage;
                $scope.count = data.data.count;

                $scope.pagination.totalPage = data.data.totalPage;
                $scope.pagination.pageHeader($scope.pageNumber);
                $scope.pagination.searchParams = body;
                /!*  宝宝树66小区二次改造    add   chenf  20170821   start   追加举报区分闲置和帖子*!/
                $scope.statusFlg = body.statusFlg;
                /!*  宝宝树66小区二次改造    add   chenf  20170821   end   追加举报区分闲置和帖子*!/   旧*/

                if(data!=null&&data.data!=null&&data.data.status==999)
                {
                    alert(data.data.message);
                }
                else {
                    $scope.questionList = data.data.list;
                    $scope.pageNumber = data.data.totalPage;
                    $scope.count = data.data.count;

                    $scope.pagination.totalPage = data.data.totalPage;
                    $scope.pagination.pageHeader($scope.pageNumber);
                    $scope.pagination.searchParams = body;
                    /*  宝宝树66小区二次改造    add   chenf  20170821   start   追加举报区分闲置和帖子*/
                    $scope.statusFlg = body.statusFlg;
                    /*  宝宝树66小区二次改造    add   chenf  20170821   end   追加举报区分闲置和帖子*/
                }
                /*  宝宝树66小区二次改造    mod   gct  20170901   end   */
            }).error(function () {
                $scope.questionList = null;
            });
        };
        /*  宝宝树66小区二次改造    add   chenf  20170821   start   追加查看图片*/
        $scope.readPicture = function (question) {
            if(question.images !== null){
                question.images.forEach(function(temp) {
                    if(temp.imageURL.indexOf('http://'+ imgHost) == -1){
                        temp.imageURL = 'http://'+ imgHost+ temp.imageURL;
                    }
                });
            }
            $scope.imagsList = question.images;
            $('#images').modal({target: '#images', width: 1000, height: 520});
        }
        /*  宝宝树66小区二次改造    add   chenf  20170821   end   */



        //删除问题
        $scope.deleteQuestionReport = function (question, index) {
            /*宝宝树66小区二次改造    mod   chenf  20170822   start   追加举报区分闲置和帖子*/
            var body = {};
            // 帖子，闲置区分
            var statusFlg = $('#statusFlg').val();
            body.statusFlg = statusFlg;
            // 帖子
            if (statusFlg == 1){
                body.objId = question.question.objId;
            }else{
                // 闲置
                body.objId = question.goods.objId;
            }

            //console.debug(question);
            /*$http.post('http://' + backOfficeHost + '/rest/v1.0/mis/question/deleteQuestionReport',{question:question.question.objId}, {*/
            $http.post('http://' + backOfficeHost + '/rest/v1.0/mis/question/deleteQuestionReport',body, {
            /*宝宝树66小区二次改造    mod   chenf  20170821   end   追加举报区分闲置和帖子*/
                headers: {'Content-Type': 'application/json;charset=utf-8'}
            }).success(function (data) {
                if (data.result.status == 1) {
                    /*宝宝树66小区二次改造    mod   chenf  20170822   start   追加举报区分闲置和帖子*/
                    /*$('#delete-confirm-'+index).modal("close");*/
                    // 帖子
                    if (statusFlg == 1){
                        $('#delete-confirm-'+index).modal("close");
                    }else{
                        // 闲置
                        $('#delete-confirm2-'+index).modal("close");
                    }
                    /*宝宝树66小区二次改造    mod   chenf  20170822   end   追加举报区分闲置和帖子*/
                    $scope.searchReport(true);
                }else {
                    alert('删除失败');
                }
            }).error(function () {

            });
        };

        $scope.rejectQuestionReport = function (question, index) {
            /*宝宝树66小区二次改造    mod   chenf  20170822   start   追加举报区分闲置和帖子*/
            var body = {};
            // 帖子，闲置区分
            var statusFlg = $('#statusFlg').val();
            body.statusFlg = statusFlg;
            // 帖子
            if (statusFlg == 1){
                body.objId = question.question.objId;
            }else{
                // 闲置
                body.objId = question.goods.objId;
            }
            //console.debug(question);
            /*$http.post('http://' + backOfficeHost + '/rest/v1.0/mis/question/rejectQuestionReport',{question:question.question.objId}, {*/
            $http.post('http://' + backOfficeHost + '/rest/v1.0/mis/question/rejectQuestionReport',body, {
            /*宝宝树66小区二次改造    mod   chenf  20170821   end   追加举报区分闲置和帖子*/
                headers: {'Content-Type': 'application/json;charset=utf-8'}
            }).success(function (data) {
                if (data.result.status == 1) {
                    /*宝宝树66小区二次改造    mod   chenf  20170822   start   追加举报区分闲置和帖子*/
                    /*$('#reject-confirm-'+index).modal("close");*/
                    // 帖子
                    if (statusFlg == 1){
                        $('#reject-confirm-'+index).modal("close");
                    }else{
                        // 闲置
                        $('#reject-confirm2-'+index).modal("close");
                    }
                    /*宝宝树66小区二次改造    mod   chenf  20170822   end   追加举报区分闲置和帖子*/
                    $scope.searchReport(true);
                }else {
                    alert('忽略失败');
                }
            }).error(function () {

            });
        };



        //级联框
        var cascadData = {
            provinceUrl: 'http://' + backOfficeHost + '/rest/v1.0/backoffice/region/regionPrivince',
            cityUrl: 'http://' + backOfficeHost + '/rest/v1.0/backoffice/region/regionCity',
            cityAreaUrl: 'http://' + backOfficeHost + '/rest/v1.0/backoffice/region/regionCounty',
            villageUrl: 'http://' + backOfficeHost + '/rest/v1.0/mis/community/communityList',
            ajax: $http
        };
        $scope.cascading = new gObj.cascading(cascadData);
        $scope.cascading.paint($(".city-cascading")[0],true);

    }]).controller('questionPushCtrl', ['$scope','$http','$routeParams','$location', function ($scope, $http,$routeParams,$location) {

        $scope.currentPage = 1;
        $scope.pageSize = 15;
        $scope.isQueryThatUser = false;
        //分页
        $scope.pagination = new pagination({currentPage:$scope.currentPage,pageSize: $scope.pageSize,
            url:'http://' + backOfficeHost + '/rest/v1.0/mis/question/questionPushList/:page/:size',
            ajax: $http,
            success:function(data){
                $scope.questionList = GetCategoryName(data.data.list,'image');
                $scope.pageNumber = data.data.totalPage;
                $scope.count = data.data.count;
                $scope.currentPage = $(".am-active").text();
                $scope.pagination.totalPage = data.data.totalPage;
                $scope.pagination.pageHeader($scope.pageNumber);
                //console.debug(params);
                $('#count').text("共"+$scope.pageNumber+"页 有"+$scope.count+"数据");
            },
            error: function(err){
                $scope.questionList = null;
            },
            params: {}
        });

        //搜索
        $scope.search = function (current) {

            if (current) {
                $scope.currentPage = $scope.pagination.currentPage;
            }else {
                $scope.pagination.currentPage = 1;
                $scope.currentPage = 1;
            }

            var community = $scope.cascading.getVillageId(document.getElementById("search-target"));
            var body = {};

            if (community) body.community = community;
            if ($scope.nickName) body.nickName = $scope.nickName;
            if ($scope.createdBy) body.createdBy = $scope.createdBy;
            if ($scope.desc) body.desc = $scope.desc;
            if ($scope.tag != '') body.tag = $scope.tag;
            if ($scope.replies != '') body.replies = $scope.replies;
            if ($scope.level != '') body.level = $scope.level;
            if ($scope.acrossCity != '') body.acrossCity = $scope.acrossCity;
            if ($scope.sort) body.sort = true;
            if ($scope.category) body.category = $scope.category;

            if ($("#startDate").val()) body.startDate = $("#startDate").val() + ':00';
            if ($("#endDate").val()) body.endDate = $("#endDate").val() + ':00';
            if (body.startDate && body.endDate && body.startDate > body.endDate) {
                alert('开始日期不能大于结束日期');
                return;
            }


            $http.post('http://' + backOfficeHost + '/rest/v1.0/mis/question/questionPush/' + $scope.currentPage + '/' + $scope.pageSize, body, {
                headers: {'Content-Type': 'application/json;charset=utf-8'}
            }).success(function (data) {

                $scope.questionList = GetCategoryName(data.data.list,'image');
                $scope.pageNumber = data.data.totalPage;
                $scope.count = data.data.count;

                $scope.pagination.totalPage = data.data.totalPage;
                $scope.pagination.pageHeader($scope.pageNumber);
                $scope.pagination.searchParams = body;

                $('#loading').modal("close");

            }).error(function (err) {

                $('#loading').modal("close");

                $scope.questionList = null;
                alert(err);
            });
        };

        $scope.pushQuestion;
        $scope.questionPushShow = function (question){

            $scope.pushQuestion = question;

            $('#doc-modal-push').modal({target: '#doc-modal-push', width: 800, height: 360 });

        };

        $scope.questionPush = function (message){

            var opt ={
                openType :1,
                contentId:  $scope.pushQuestion.objId,
                createdBy:  $scope.pushQuestion.createdBy.objId,
                tag:  '话题',
                message: message,
                aroundCommunity : $scope.pushQuestion.aroundCommunity
            };

            $http.post('http://' + backOfficeHost + '/rest/v1.0/mis/question/questionPush', opt, {
                headers: {'Content-Type': 'application/json;charset=utf-8'}
            }).success(function (data) {

                $('#doc-modal-push').modal("close");
                $('#loading').modal("close");
                if (data.result.status == 1) {
                    alert('推送成功!');
                }else{
                    alert('推送失败!');
                };

            }).error(function (err) {
                $('#doc-modal-push').modal("close");
                $('#loading').modal("close");

                $scope.questionList = null;
                alert(err);
            });
        };

    }]).controller('questionReplyCtrl', ['$scope','$http','$routeParams','$location', function ($scope, $http,$routeParams,$location) {

        $scope.currentPage = 1;
        $scope.pageSize = 15;


        //分页
        $scope.pagination = new pagination({currentPage:$scope.currentPage,pageSize: $scope.pageSize,
            url:'http://' + backOfficeHost + '/rest/v1.0/mis/question/questionReplyList/:page/:size',
            ajax: $http,
            success:function(data){
                $scope.resultList = data.data.list;
                $scope.pageNumber = data.data.totalPage;
                $scope.count = data.data.count;
                $scope.currentPage = $(".am-active").text();
                $scope.pagination.totalPage = data.data.totalPage;
                $scope.pagination.pageHeader($scope.pageNumber);
            },
            error: function(err){

            },
            params: {replyStatus:-1}
        });


        $scope.search = function(current) {

            if (current) {
                $scope.currentPage = $scope.pagination.currentPage;
            }else {
                $scope.pagination.currentPage = 1;
                $scope.currentPage = 1;
            }

            var body = {};
            if ($scope.replyBy) {
                body.replyBy = $scope.replyBy;
                sessionStorage.setItem('questionReplyCtrl_replyBy',body.replyBy);
            }else
            {
                body.replyBy = sessionStorage.getItem('questionReplyCtrl_replyBy');
                $scope.replyBy = body.replyBy;
            }
            if ($scope.replyDesc) body.replyDesc = $scope.replyDesc;

            if(!body.replyBy){
                alert('请输入回复者ID');
                $('#loading').modal("close");
                return;
            }

            $('#loading').modal({target: '#loading'});

            $http.post('http://' + backOfficeHost + '/rest/v1.0/mis/question/questionReplyList/' + $scope.currentPage + '/' + $scope.pageSize, body, {
                headers: {'Content-Type': 'application/json;charset=utf-8'}
            }).success(function (data) {
                //console.debug(data);
                $scope.resultList = data.data.list;
                $scope.pageNumber = data.data.totalPage;
                $scope.count = data.data.count;
                $('#loading').modal("close");
                $scope.pagination.totalPage = data.data.totalPage;
                $scope.pagination.pageHeader($scope.pageNumber);
                $scope.pagination.searchParams = body;

            }).error(function (err) {
                $('#loading').modal("close");
                $scope.resultList = null;
            });
        };

        $scope.deleteReply = function(reply,index) {

            var opt ={
                contentId:reply.contentId,
                replyId:reply.replyId,
                replyBy:reply.repliedBy.objId
            };

            $http.post('http://' + backOfficeHost + '/rest/v1.0/mis/question/deleteReply',opt, {
                headers: {'Content-Type': 'application/json;charset=utf-8'}
            }).success(function (data) {
                if (data.result.status == 1) {
                    $('#delete-confirm-'+index).modal("close");
                    //$('#loading').modal({target: '#loading'});
                    $scope.search(true);
                    $scope.resultList.splice(index,1);
                }else {
                    alert('删除失败');
                }
            }).error(function () {

            });

        };
    /*  宝宝树66小区二次改造    add   gct  20170821   start   */
    }]).controller('personalLetterCtrl', ['$scope','$http','$routeParams','$location', function ($scope, $http, $routeParams, $location) {


    $scope.currentPage = 1;
    $scope.pageSize = 15;

    var model = $routeParams.model;
    var params = {};
    if(model == '1'){
        params.status = 1;
        $scope.status = 1;
    };

    //分页
    $scope.pagination = new pagination({currentPage:$scope.currentPage,pageSize: $scope.pageSize,
        url:'http://' + backOfficeHost + '/rest/v1.0/mis/question/personalLetterAtList/:page/:size',
        ajax: $http,
        success:function(data){
            $scope.atList = data.data.list;
            $scope.pageNumber = data.data.totalPage;
            $scope.count = data.data.count;

            $scope.currentPage = $(".am-active").text();
            $scope.pagination.totalPage = data.data.totalPage;
            $scope.pagination.pageHeader($scope.pageNumber);
            $('#count').text("共"+$scope.pageNumber+"页 有"+$scope.count+"数据");
        },
        error: function(err){
            $scope.atList = null;
        },
        params: params
    });

    //全选列表
    $scope.allSelected = function(){
        $scope.pagination.allSelected();
    };


  /*  $scope.update = function (at) {

        var body = {id:at.objId, status:false};

        $http.post('http://' + backOfficeHost + '/rest/v1.0/mis/question/replyAtUpdate', body, {
            headers: {'Content-Type': 'application/json;charset=utf-8'}
        }).success(function (data) {
            at.status = false;
        }).error(function (err) {
            alert(err);
        });
    };*/

    $scope.replyMessage = function (id){
       /* $("#replyMessage_box").css("display","block");
        $("#replyMessageMask_box").css("display","block");*/
        $("#replyMessageIframe_box").attr("src","../../partials/cs/atcs_replyMessage.html?id="+id);
        //location.href = "../../partials/cs/atcs_detail.html?contentId="+contentId+"&category="+category;
    }

    //搜索
    $scope.search = function (btn) {

        var opt = {};
        if ($scope.status) opt.status = $scope.status;

        $http.post('http://' + backOfficeHost + '/rest/v1.0/mis/question/personalLetterAtList/:' + 1 + '/' + $scope.pageSize, opt, {
            headers: {'Content-Type': 'application/json;charset=utf-8'}
        }).success(function (data) {
            $scope.atList = data.data.list;
            $scope.pageNumber = data.data.totalPage;
            $scope.count = data.data.count;

            $scope.pagination.totalPage = data.data.totalPage;
            $scope.pagination.pageHeader($scope.pageNumber);
            $scope.pagination.searchParams = opt;
        }).error(function (err) {
            alert(err);
        });

    };


}])
/*  宝宝树66小区二次改造    add   gct  20170821   end   */